package setup;

import adapter.Adapter;
import player.PlayerController;
import field.FieldController;
import game.Game;

public class Setup {

	private Gameboard gameboard;
	private PlayerController playerC;
	private FieldController fieldC;
	private FileLoad loader;
	private Game game;
	private int players = 0, money;
	private boolean fieldPlacement;
	private String rounds;

	/**
	 * Opretter gameboard, spillere m.m.
	 * @param fieldPlacement 
	 * @param rounds 
	 * @param money 
	 * @param players 
	 */
	public void createGame(){
		
		while (players == 0){
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				System.out.println("System crashed. To bad!");
				e.printStackTrace();
			}
		}
		
		loader = new FileLoad();
		loader.readFieldPrice();
		loader.readFieldRent();
		gameboard = new Gameboard();
		
		fieldC = new FieldController();
		fieldC.createFields(loader.getFieldPrices(), loader.getFieldRent(), loader.getFieldTitles(), loader.getFieldSubtitles(), loader.getFieldDesc(), loader.getLuckText());
		
		if (fieldPlacement == true){
			gameboard.shuffle(fieldC.getFields());
		}
		gameboard.createGuiFields(fieldC.getFields()); // Opretter gui-felterne samt sender dem til GUI'en den definerede rækkefølge
 
		Adapter adapter = new Adapter(gameboard.getGuiFields()); // Opretter en adapter der indeholder GUIfields
		fieldC.setAdapter(adapter);
		
		playerC = new PlayerController(players, money);
		playerC.createPlayers();

		game = new Game(playerC, fieldC);
		game.startSpil(rounds);
	}
	
	public void setChoices(int players, int money, boolean fieldPlacement, String rounds){
		this.players = players;
		this.money = money;
		this.fieldPlacement = fieldPlacement;
		this.rounds = rounds;
	}
}